
function http(url,method,data){
  var base = "https://api.xintujing.cn/";
  wx.showLoading({
    title: '加载中...',
    mask:true
  });
  return new Promise((resolve,reject)=>{
    wx.request({
      url:base+url,
      method:method,
      data: data,
      header: {//content-type": "application/x-www-form-urlencoded
        'content-type': 'application/json'
      },
      success:res=>{
        console.log(res);
        if (res.statusCode==200){
          resolve(res);
          wx.hideLoading();
        }else{
          wx.hideLoading();
          wx.showModal({
            title: '失败',
            content: '数据请求失败，是否返回主页',
            showCancel:false,
            success:as=>{
              if(as.confirm){
                wx.switchTab({
                  url: '/pages/index/index',
                })
              }
            }
          })
        }
      },
      fail:msg=>{
        console.log(msg.errMsg);
        reject(msg);
      }
    })
  });
}
//首页轮播图数据渲染
function banner(data){
  return http('v1/courseBanner/all','get',data);
}
//首页导航数据渲染
function nav(data) {
  return http('v1/shopCourse/listCategory', 'get', data);
}
//首页列表数据渲染
function list(data) {
  return http('v1/shopCourse/findCourse', 'get', data);
}
//搜索页面数据渲染接口
function search_hot(data){
  return http('v1/product/course/hot', 'get', data);
}
//搜索页面，搜索出的数据请求接口
function search_hot_list(data){
  return http('v1/product/course/search','post',data);
}
//首页点击到详情页数据渲染https://api.xintujing.cn/v1/shop/product?course_id=688
function index_xq(data) {
  return http('v1/shop/product', 'get', data);
}
//详情页点击导航触发目录接口https://api.xintujing.cn/v1/course/chapter/listChapterAndLesson?course_id=688
function index_xq_menu(data) {
  return http('v1/course/chapter/listChapterAndLesson', 'get', data);
}
//详情页问答接口https://api.xintujing.cn/v1/course/qa/list?course_id=694
function index_xq_wenDa(data) {
  return http('v1/course/qa/list', 'get', data);
}
function shop(data){
  return http('v1/shopInfo/shopList',"get",data)
}
module.exports={
  banner:banner,
  nav:nav,
  list:list,
  search_hot: search_hot,
  search_hot_list: search_hot_list,
  index_xq: index_xq,
  index_xq_menu: index_xq_menu,
  index_xq_wenDa: index_xq_wenDa,
  shop:shop
}